﻿using System;
using System.Windows.Forms;
using Microsoft.Xna.Framework.Graphics;

namespace Sample05
{
    public partial class Main : Form, IEditorHost 
    {
        // 编辑器主类，从引擎类继承
        private Sample05 editor;

        // 是否已经完成了列表的填充？
        bool hasFillListAvailableEffect = false;
        
        public Main()
        {
            InitializeComponent();            
        }

        #region 实现IWinForm接口和IEditorHost接口的成员

        public Form Form
        {
            get { return this; }
        }

        public Control winControl
        {
            get { return splitContainer1 .Panel1 ; }
        }

        public Sample05 Editor
        {
            set { editor = value; }
        }

        #endregion        

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void lstAvailableEffect_DoubleClick(object sender, EventArgs e)
        {
            lstActiveEffect.Items.Add(lstAvailableEffect.Text);
            editor.SceneManager .ActiveScene.AddPostEffect (lstAvailableEffect.Text);
        }

        private void lstActiveEffect_DoubleClick(object sender, EventArgs e)
        {
            lstActiveEffect.Items.Remove(lstActiveEffect.Text);
            editor.SceneManager.ActiveScene.RemovePostEffect (lstAvailableEffect.Text);
        }

        private void tkbBlurSize_Scroll(object sender, EventArgs e)
        {
            Sample05.PPEffect.Parameters["BlurSize"].SetValue(((TrackBar)sender).Value / 10f);
        }

        private void tkbSharpAmount_Scroll(object sender, EventArgs e)
        {
            Sample05.PPEffect.Parameters["SharpAmount"].SetValue(((TrackBar)sender).Value);
        }

        private void Main_Activated(object sender, EventArgs e)
        {
            if (!hasFillListAvailableEffect)
            {
                foreach (EffectTechnique effect in Sample05.PPEffect.Techniques)
                {
                    lstAvailableEffect.Items.Add(effect.Name);
                }
                hasFillListAvailableEffect = true;
            }
        }
    }
}
